﻿using System;
using System.Collections.Generic;
using Ext.Net;
using BLL;
using Model;
using System.Xml;
using System.Xml.Xsl;

namespace Web.View.d60_qtdj_lsMenu
{
    public partial class Default : UIPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        //绑定Grid
        protected void d60_qtdj_ls_DataBind(object sender, StoreRefreshDataEventArgs e)
        {
            d60_qtdj_lsMgr mgr = new d60_qtdj_lsMgr();
            e.Total = int.Parse(mgr.GetRecordCount_d60_qtdj_ls(e.Parameters[d60_qtdj_ls_Filter.ParamPrefix]));
            IList<d60_qtdj_ls> list = mgr.FindAllByPage_d60_qtdj_ls(e.Start.ToString(), e.Limit.ToString(), e.Parameters[d60_qtdj_ls_Filter.ParamPrefix]);
            d60_qtdj_ls_MainStore.DataSource = list;
            d60_qtdj_ls_MainStore.DataBind();
        }
        //删除数据
        protected void BtnDel_Click(object sender, DirectEventArgs e)
        {
            d60_qtdj_lsMgr mgr = new d60_qtdj_lsMgr();
            RowSelectionModel sm = d60_qtdj_ls_Grid.SelectionModel.Primary as RowSelectionModel;
            foreach (SelectedRow row in sm.SelectedRows)
            {
                d60_qtdj_ls _d60_qtdj_ls = new d60_qtdj_ls();
                _d60_qtdj_ls.jsdh = row.RecordID;//int.Parse(row.RecordID);
                if (mgr.Del_d60_qtdj_ls(_d60_qtdj_ls))
                {
                    log.Debug("d60_qtdj_ls中执行了删除，并成功");
                    X.Msg.Notify("成功", "<font color='green'>已经成功删除选中的记录</font>").Show();
                }
                else
                    X.Msg.Notify("失败", "<font color='green'>删除记录失败，请您重试！</font>").Show();
            }
            d60_qtdj_ls_Grid.Reload();
        }
        protected void BtnSave_Click(object sender, DirectEventArgs e)
        {
            d60_qtdj_lsMgr mgr = new d60_qtdj_lsMgr();
            d60_qtdj_ls _d60_qtdj_ls = new d60_qtdj_ls();
            if (Hid.Text.Length > 0)
                _d60_qtdj_ls = mgr.FindById_d60_qtdj_ls(int.Parse(Hid.Text));
            
			_d60_qtdj_ls.dqbm = Txtdqbm.Text.Trim();
			_d60_qtdj_ls.dzbm = Txtdzbm.Text.Trim();
			_d60_qtdj_ls.zbh = Txtzbh.Text.Trim();
			_d60_qtdj_ls.cbh = Txtcbh.Text.Trim();
			_d60_qtdj_ls.zyid = Txtzyid.Text.Trim();
			_d60_qtdj_ls.grbm = Txtgrbm.Text.Trim();
			_d60_qtdj_ls.hzxm = Txthzxm.Text.Trim();
			_d60_qtdj_ls.rbh = Txtrbh.Text.Trim();
			_d60_qtdj_ls.brxm = Txtbrxm.Text.Trim();
			_d60_qtdj_ls.xb = Txtxb.Text.Trim();
			_d60_qtdj_ls.brnl = Txtbrnl.Text.Trim();
			_d60_qtdj_ls.hzgx = Txthzgx.Text.Trim();
			_d60_qtdj_ls.sfzh = Txtsfzh.Text.Trim();
			_d60_qtdj_ls.hkdz = Txthkdz.Text.Trim();
			_d60_qtdj_ls.hbh = Txthbh.Text.Trim();
			_d60_qtdj_ls.ylzh = Txtylzh.Text.Trim();
			_d60_qtdj_ls.zybh = Txtzybh.Text.Trim();
			_d60_qtdj_ls.jjlx = Txtjjlx.Text.Trim();
			_d60_qtdj_ls.rysj = Txtrysj.Text.Trim();
			_d60_qtdj_ls.cysj = Txtcysj.Text.Trim();
			_d60_qtdj_ls.zycs = int.Parse(TxtNumzycs.Text.Trim());
			_d60_qtdj_ls.zyts = int.Parse(TxtNumzyts.Text.Trim());
			_d60_qtdj_ls.jgdm = Txtjgdm.Text.Trim();
			_d60_qtdj_ls.jgjb = Txtjgjb.Text.Trim();
			_d60_qtdj_ls.ryzd = Txtryzd.Text.Trim();
			_d60_qtdj_ls.zdmc = Txtzdmc.Text.Trim();
			_d60_qtdj_ls.fyhj = Txtfyhj.Text.Trim();
			_d60_qtdj_ls.mxhj = Txtmxhj.Text.Trim();
			_d60_qtdj_ls.kbhj = Txtkbhj.Text.Trim();
			_d60_qtdj_ls.shkbje = Txtshkbje.Text.Trim();
			_d60_qtdj_ls.zfhj = Txtzfhj.Text.Trim();
			_d60_qtdj_ls.sjhj = Txtsjhj.Text.Trim();
			_d60_qtdj_ls.cehj = Txtcehj.Text.Trim();
			_d60_qtdj_ls.bsbl = Txtbsbl.Text.Trim();
			_d60_qtdj_ls.sfje = Txtsfje.Text.Trim();
			_d60_qtdj_ls.fdje = Txtfdje.Text.Trim();
			_d60_qtdj_ls.czry = Txtczry.Text.Trim();
			_d60_qtdj_ls.hsry = Txthsry.Text.Trim();
			_d60_qtdj_ls.shry = Txtshry.Text.Trim();
			_d60_qtdj_ls.fkry = Txtfkry.Text.Trim();
			_d60_qtdj_ls.cnry = Txtcnry.Text.Trim();
			_d60_qtdj_ls.zljg = Txtzljg.Text.Trim();
			_d60_qtdj_ls.hsjg = Txthsjg.Text.Trim();
			_d60_qtdj_ls.shjg = Txtshjg.Text.Trim();
			_d60_qtdj_ls.hkjg = Txthkjg.Text.Trim();
			_d60_qtdj_ls.clrq = Txtclrq.Text.Trim();
			_d60_qtdj_ls.hsrq = Txthsrq.Text.Trim();
			_d60_qtdj_ls.shrq = Txtshrq.Text.Trim();
			_d60_qtdj_ls.bcrq = Txtbcrq.Text.Trim();
			_d60_qtdj_ls.ecje = Txtecje.Text.Trim();
			_d60_qtdj_ls.shdfbz = Txtshdfbz.Text.Trim();
			_d60_qtdj_ls.bz = Txtbz.Text.Trim();
			_d60_qtdj_ls.hkbz = Txthkbz.Text.Trim();
			_d60_qtdj_ls.bzxx = Txtbzxx.Text.Trim();
			_d60_qtdj_ls.szbz = Txtszbz.Text.Trim();
			_d60_qtdj_ls.fpid = Txtfpid.Text.Trim();
			_d60_qtdj_ls.zt = Txtzt.Text.Trim();
			_d60_qtdj_ls.jzks = Txtjzks.Text.Trim();
			_d60_qtdj_ls.jzys = Txtjzys.Text.Trim();
			_d60_qtdj_ls.hsx = Txthsx.Text.Trim();
			_d60_qtdj_ls.chsx = Txtchsx.Text.Trim();
			_d60_qtdj_ls.dybz = Txtdybz.Text.Trim();
			_d60_qtdj_ls.fphm = Txtfphm.Text.Trim();
			_d60_qtdj_ls.ljzyfy = Txtljzyfy.Text.Trim();
			_d60_qtdj_ls.ljzykb = Txtljzykb.Text.Trim();
			_d60_qtdj_ls.ljzybc = Txtljzybc.Text.Trim();
			_d60_qtdj_ls.yphj = Txtyphj.Text.Trim();
			_d60_qtdj_ls.yphjkb = Txtyphjkb.Text.Trim();
			_d60_qtdj_ls.lxdh = Txtlxdh.Text.Trim();
			_d60_qtdj_ls.ybje = Txtybje.Text.Trim();

            bool isok = false;
            if (Hid.Text.Length > 0)
                isok = mgr.Update_d60_qtdj_ls(_d60_qtdj_ls);
            else
                isok = mgr.Add_d60_qtdj_ls(_d60_qtdj_ls);
            if (isok)
            {
                d60_qtdj_ls_Win.Hide();
                X.Msg.Notify("成功", "<font color='green'>恭喜您，操作成功！</font>").Show();
                log.Debug("d60_qtdj_ls中执行了保存（插入或修改），并成功");
                d60_qtdj_ls_Grid.Reload();
            }
            else
                X.Msg.Notify("失败", "<font color='red'>操作失败，请您重试！</font>").Show();
        }
        //数据保存为Excel
        protected void BtnSaveToExcel(object sender, EventArgs e)
        {
            string json = ExcelGridData.Value.ToString();
            StoreSubmitDataEventArgs eSubmit = new StoreSubmitDataEventArgs(json, null);
            XmlNode xml = eSubmit.Xml;
            this.Response.Clear();
            this.Response.ContentType = "application/vnd.ms-excel";
            this.Response.AddHeader("Content-Disposition", "attachment; filename=QiDian10Excel.xls");
            XslCompiledTransform xtExcel = new XslCompiledTransform();
            xtExcel.Load(Server.MapPath("/View/ExcelTemp/Excel.xsl"));
            xtExcel.Transform(xml, null, this.Response.OutputStream);
            this.Response.End();

        }
    }
}